package com.muyu.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.system.domain.DanmoMarketOrder;
import com.muyu.system.service.IDanmoMarketOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户订单Controller
 *
 * @author yangle
 * @date 2024-09-08
 */
@RestController
@RequestMapping("/order")
public class DanmoMarketOrderController extends BaseController {
    @Autowired
    private IDanmoMarketOrderService danmoMarketOrderService;

    /**
     * 查询用户订单列表
     */
//    @RequiresPermissions("system:order:list")
    @PostMapping("/list")
    public Result list(@RequestBody  DanmoMarketOrder danmoMarketOrder) {
        PageHelper.startPage(danmoMarketOrder.getPageNum(),danmoMarketOrder.getPageSize());

        List<DanmoMarketOrder> list = danmoMarketOrderService.selectDanmoMarketOrderList(danmoMarketOrder);
        PageInfo<DanmoMarketOrder> danmoMarketOrderPageInfo = new PageInfo<>(list);
        return Result.success(danmoMarketOrderPageInfo);
    }

    /**
     * 导出用户订单列表
     */
//    @RequiresPermissions("system:order:export")
    @Log(title = "用户订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoMarketOrder danmoMarketOrder) {
        List<DanmoMarketOrder> list = danmoMarketOrderService.selectDanmoMarketOrderList(danmoMarketOrder);
        ExcelUtil<DanmoMarketOrder> util = new ExcelUtil<DanmoMarketOrder>(DanmoMarketOrder.class);
        util.exportExcel(response, list, "用户订单数据");
    }



    /**
     * 获取用户订单详细信息
     */
//    @RequiresPermissions("system:order:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return success(danmoMarketOrderService.selectDanmoMarketOrderById(id));
    }

    /**
     * 新增用户订单
     */
    //   @RequiresPermissions("system:order:add")
    @Log(title = "用户订单", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoMarketOrder danmoMarketOrder) {
        return toAjax(danmoMarketOrderService.insertDanmoMarketOrder(danmoMarketOrder));
    }

    /**
     * 修改用户订单
     */
    //   @RequiresPermissions("system:order:edit")
    @Log(title = "用户订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoMarketOrder danmoMarketOrder) {
        return toAjax(danmoMarketOrderService.updateDanmoMarketOrder(danmoMarketOrder));
    }

    /**
     * 删除用户订单
     */
//    @RequiresPermissions("system:order:remove")
    @Log(title = "用户订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(danmoMarketOrderService.deleteDanmoMarketOrderByIds(ids));
    }

    /**
     * 添加订单
     */
    @PostMapping("/addOrder")
    public Result addOrder(@RequestBody DanmoMarketOrder danmoMarketOrder) {
        danmoMarketOrderService.addOrder(danmoMarketOrder);
        return Result.success("添加成功");
    }
}